package org.dromara.system.service.impl.trading.channel;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.json.JSONUtil;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.exception.BusinessException;
import org.dromara.system.config.core.RedisDelayMQSender;
import org.dromara.system.converter.MachineConverters;
import org.dromara.system.domain.ProductLineInformation;
import org.dromara.system.domain.TradingRecords;
import org.dromara.system.domain.bo.lsqdb.LSQDBTradingWaterBo;
import org.dromara.system.domain.bo.lsqdb.LSQDSignBo;
import org.dromara.system.domain.vo.lsqdb.LSQDTradingVo;
import org.dromara.system.enums.NotificationEnum;
import org.dromara.system.enums.RedisMQConstant;
import org.dromara.system.service.impl.trading.AbstractTradingService;
import org.dromara.system.util.JsonUtil;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@Slf4j
@Service("lSQDTradingService")
@RequiredArgsConstructor
public class LSQDTradingService extends AbstractTradingService<Object, LSQDBTradingWaterBo> {


    @Resource
    private RedisDelayMQSender redisDelayMQSender;


    @Override
    public NotificationEnum getNotificationEnum() {
        return NotificationEnum.LS_QD;
    }

    @Override
    public void tradingWaterConvert(LSQDBTradingWaterBo reqDTO) {
        TradingRecords tradingRecords = MachineConverters.INSTANCE.lSQDRecordsToReceiveDealRecords(reqDTO);
        tradingRecords.setTradingTime(DateUtil.date());
        R<TradingRecords> tradingRecordsR = dealUserTrading(tradingRecords);
    }

    @Override
    public Object tradingWaterAssemble(String mapBody, Integer mark) {
        log.info("乐刷渠道版交易入参=={}", mapBody);
        LSQDSignBo reqDTO = JSONUtil.toBean(JSONUtil.parseObj(mapBody), LSQDSignBo.class);
        ProductLineInformation productLineInformation = getBrandProductsLineById(mark);
        BusinessException.isNull(productLineInformation, "关联权限不存在");
        String data = reqDTO.getData();
        LSQDBTradingWaterBo bo = JSONUtil.toBean(data, LSQDBTradingWaterBo.class);
        redisDelayMQSender.send(RedisMQConstant.TRADING_QUEUE,
            JsonUtil.toJSONString(bo), getNotificationEnum(), Convert.toStr(bo.getOrderno()));
        return new LSQDTradingVo();
    }


}
